home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / ace23.lha / AIDE.lha / aide.b < prev    next >
Text File  |  1994-10-22  |  45KB  |  1,801 lines

  1. {*
  2. ** ACE Integrated Development Environment: AIDE **
  3. **
  4. ** Author: David J Benn
  5. **   Date: 23rd,24th,28th-31st December 1993,
  6. **       1st-3rd,5th,6th,8th,10th-12th,
  7. **       14th,15th,17th,19th,23rd,24th January 1994,
  8. **       3rd,4th,6th,8th,12th,15th,26th,28th February 1994,
  9. **       1st,6th March 1994,
  10. **       3rd,4th,11th April 1994,
  11. **       31st July 1994,
  12. **       18th September 1994,
  13. **       2nd,9th October 1994
  14. *}
  15.  
  16. '..version information
  17. STRING vernum SIZE 5
  18. vernum = "1.1"
  19. version$ = "$VER: AIDE 1.1 (09.10.94)"
  20.  
  21. DEFLNG a-z
  22.  
  23. {*
  24. ** Menu Constants (prefixes: c=command, m=menu, i=menu item)
  25. *}
  26.  
  27. '..basic values
  28. CONST TRUE     =-1&
  29. CONST FALSE     =0&
  30. CONST NULL     =0&
  31.  
  32. '..Object file types
  33. CONST ASM     =1
  34. CONST OBJ     =2
  35. CONST EXE     =3
  36.  
  37. '..Modes
  38. CONST cDisable     =0
  39. CONST cEnable      =1
  40. CONST cCheck     =2
  41.  
  42. '..Project Menu
  43. CONST mProject     =1
  44. CONST iNew     =1
  45. CONST iOpen     =2
  46. CONST iView     =3
  47. CONST iSep1.1     =4
  48. CONST iDelete     =5
  49. CONST iPrint     =6
  50. CONST iExecute     =7
  51. CONST iShell     =8
  52. CONST iSep1.2     =9
  53. CONST iAbout     =10
  54. CONST iQuit     =11
  55.  
  56. '..Program Menu
  57. CONST mProgram     =2
  58. CONST iSetSource =1
  59. CONST iEdit     =2
  60. CONST iSep2.1     =3
  61. CONST iRun     =4
  62. CONST iRunInShell=5
  63. CONST iSep2.2     =6
  64. CONST iCompile     =7
  65. CONST iMake     =8
  66. CONST iBuild     =9
  67. CONST iModule      =10
  68. CONST iSep2.3     =11
  69. CONST iViewAsm     =12
  70. CONST iViewPrep     =13
  71. CONST iShowErrs     =14
  72.  
  73. '..Compiler Menu
  74. CONST mCompiler     =3
  75. CONST iPreProcess=1
  76. CONST iBreak     =2
  77. CONST iComments  =3
  78. CONST iIcon     =4
  79. CONST iListLines =5
  80. CONST iOptimise  =6
  81. CONST iWindow     =7
  82. CONST iSep3.1     =8
  83. CONST iSaveOpts     =9
  84.  
  85. '..Linker
  86. CONST mLinker     =4
  87. CONST iAddModule =1
  88. CONST iRemModule =2
  89. CONST iRemAllMod =3
  90. CONST iSep4.1     =4
  91.  
  92. '..Utilities
  93. CONST mUtils     =5
  94. CONST iCalc     =1
  95. CONST iFD2BMAP     =2
  96. CONST iAB2ASCII  =3
  97.  
  98. '..Help
  99. CONST mHelp     =6
  100. CONST iAIDEDoc     =1
  101. CONST iSep6.1     =2
  102. CONST iACEDoc     =3
  103. CONST iA68KDoc     =4
  104. CONST iBlinkDoc     =5
  105. CONST iSep6.2     =6
  106. CONST iACERef     =7
  107. CONST iACEWords     =8
  108. CONST iSep6.3     =9
  109. CONST iExamples     =10
  110. CONST iSep6.4     =11
  111. CONST iACEHist     =12
  112.  
  113. '..Other stuff
  114. CONST strSize    =80
  115. CONST maxModules=10
  116.  
  117.  
  118. {*
  119. ** Structure Definitions
  120. *}
  121.  
  122. STRUCT program_info
  123.   STRING   source_file SIZE strSize
  124.   STRING   source_dir  SIZE strSize
  125.   LONGINT  made
  126.   SHORTINT module_count
  127.   STRING   default_args
  128.   STRING   xtn SIZE 5
  129. END STRUCT
  130.  
  131. STRUCT config_info
  132.   STRING editor SIZE strSize
  133.   STRING viewer SIZE strSize
  134.   STRING calc SIZE strSize
  135.   STRING agdtool SIZE strSize
  136.   STRING tmpdir SIZE strSize
  137.   STRING docdir SIZE strSize
  138.   STRING srcdir SIZE strSize
  139.   STRING bltdir SIZE strSize
  140. END STRUCT 
  141.  
  142. STRUCT options_info
  143.   LONGINT preprocess
  144.   LONGINT user_break
  145.   LONGINT asm_comments
  146.   LONGINT create_icon
  147.   LONGINT list_lines
  148.   LONGINT optimise
  149.   LONGINT window_close
  150. END STRUCT
  151.  
  152. STRUCT DateStamp
  153.   LONGINT days
  154.   LONGINT mins
  155.   LONGINT ticks
  156. END STRUCT
  157.  
  158. STRUCT FileInfoBlock
  159.   longint fib_DiskKey
  160.   longint fib_DirEntryType
  161.   string  fib_FileName size 108
  162.   longint fib_Protection
  163.   longint fib_EntryType
  164.   longint fib_Size
  165.   longint fib_NumBlocks
  166.   string  fib_Date size 12
  167.   string  fib_Comment size 80
  168.   string  fib_Reserved size 36
  169. END STRUCT
  170.  
  171.  
  172. {*
  173. ** Global Variables
  174. *}
  175.  
  176. DECLARE STRUCT program_info prog
  177. DECLARE STRUCT config_info config
  178. DECLARE STRUCT options_info options
  179.  
  180. DIM module$(maxModules)
  181. STRING default_command
  182. ADDRESS main_wdw
  183.  
  184.  
  185. {*
  186. ** Shared library function declarations (when used by more than one SUB)
  187. ** with their associated CONSTs.
  188. *}
  189.  
  190. DECLARE FUNCTION SetWindowTitles(wdw&,wdw_title$,scr_title$) LIBRARY intuition
  191. CONST  LEAVE=-1&
  192.  
  193.  
  194. {*
  195. ** Subprogram declarations
  196. *}
  197.  
  198. SUB fexists(STRING fname)
  199.   OPEN "I",#255,fname
  200.   if HANDLE(255) then
  201.     fexists=TRUE
  202.   else
  203.     fexists=FALSE
  204.   end if
  205.   CLOSE #255
  206. END SUB
  207.  
  208. SUB get_file_datestamp(STRING fname,ADDRESS ds_addr)
  209. CONST   ACCESS_READ = -2&
  210. LONGINT mylock
  211. DECLARE STRUCT FileInfoBlock file_info
  212. DECLARE STRUCT DateStamp ds,Date
  213. DECLARE FUNCTION Lock&(filename$,accessmode&) LIBRARY dos
  214. DECLARE FUNCTION UnLock(filelock&) LIBRARY dos
  215. DECLARE FUNCTION Examine(filelock&,fib_ptr&) LIBRARY dos
  216.  
  217.   '..Return the datestamp of the file.
  218.   '..No checking beyond a test for NULL lock.
  219.  
  220.   ds = ds_addr
  221.   mylock = Lock(fname,ACCESS_READ) 
  222.  
  223.   if mylock <> NULL then
  224.     Examine(mylock,file_info)
  225.     Date = @file_info->fib_Date
  226.     ds->days  = Date->days
  227.     ds->mins  = Date->mins
  228.     ds->ticks = Date->ticks
  229.     UnLock(mylock)
  230.   end if
  231. END SUB
  232.  
  233. SUB SHORTINT datestamps_different(ADDRESS ds1_addr,ADDRESS ds2_addr)
  234. DECLARE STRUCT DateStamp ds1,ds2
  235.  
  236.   '..Return TRUE if the datestamps of 2 files 
  237.   '..are different.
  238.  
  239.   ds1 = ds1_addr
  240.   ds2 = ds2_addr
  241.  
  242.   '..If one file doesn't exist but the
  243.   '..other does, then the datestamps
  244.   '..are different.
  245.   IF (ds1 = NULL and ds2 <> NULL) or (ds1 <> NULL and ds2 = NULL) THEN 
  246.      datestamps_different = TRUE
  247.      EXIT SUB
  248.   END IF
  249.  
  250.   '..If neither file exists, then the
  251.   '..datestamps aren't different.
  252.   IF ds1 = NULL and ds2 = NULL THEN
  253.      datestamps_different = FALSE
  254.      EXIT SUB
  255.   END IF
  256.  
  257.   d1=ds1->days
  258.   d2=ds2->days    
  259.   m1=ds1->mins
  260.   m2=ds2->mins    
  261.   t1=ds1->ticks
  262.   t2=ds2->ticks    
  263.  
  264.   if (d1<>d2) or (m1<>m2) or (t1<>t2) then
  265.      datestamps_different=TRUE
  266.   else
  267.      datestamps_different=FALSE
  268.   end if
  269. END SUB
  270.  
  271. SUB SHORTINT older(ADDRESS ds1_addr,ADDRESS ds2_addr)
  272. DECLARE STRUCT DateStamp ds1,ds2
  273.  
  274.   '..Return TRUE if first datestamp is older than second.
  275.   ds1 = ds1_addr
  276.   ds2 = ds2_addr
  277.  
  278.   '..If first file doesn't exist it can't
  279.   '..be older than second.
  280.   IF ds1 = NULL THEN
  281.      older = FALSE
  282.      EXIT SUB
  283.   END IF
  284.  
  285.   '..If second file doesn't exist
  286.   '..but the the first file does, 
  287.   '..the first file must be older
  288.   '..than the second.
  289.   IF ds2 = NULL THEN 
  290.      older = TRUE
  291.      EXIT SUB
  292.   END IF
  293.   
  294.   d1=ds1->days
  295.   d2=ds2->days    
  296.   m1=ds1->mins
  297.   m2=ds2->mins    
  298.   t1=ds1->ticks
  299.   t2=ds2->ticks    
  300.  
  301.   IF (d1<d2) or (d1=d2 and m1<m2) or (d1=d2 and m1=m2 and t1<t2) THEN
  302.      older = TRUE
  303.   ELSE
  304.      older = FALSE
  305.   END IF  
  306. END SUB
  307.  
  308. SUB STRING quote(STRING x)
  309. '..enclose x in quotes
  310.   quote = CHR$(34)+x+CHR$(34)
  311. END SUB
  312.  
  313. SUB enable_misc_menu_items
  314. SHARED prog, config
  315.   '..Enable all menu items disabled by setup_menus
  316.   '..whenever menus are reset.
  317.  
  318.   if config->calc<>"" then MENU mUtils,iCalc,cEnable
  319.  
  320.   '..Don't enable Program menu items if there's no source file set!
  321.   if prog->source_file = "" then exit sub
  322.  
  323.   MENU mProgram,iEdit,cEnable
  324.   MENU mProgram,iRun,cEnable
  325.   MENU mProgram,iRunInShell,cEnable
  326.   MENU mProgram,iArguments,cEnable
  327.   MENU mProgram,iCompile,cEnable
  328.   MENU mProgram,iMake,cEnable
  329.   MENU mProgram,iBuild,cEnable
  330.   MENU mProgram,iModule,cEnable
  331.   MENU mProgram,iViewAsm,cEnable
  332.   MENU mProgram,iViewPrep,cEnable
  333.   MENU mProgram,iShowErrs,cEnable  
  334. END SUB
  335.  
  336. SUB menus_off
  337.   for i=mProject to mHelp
  338.     MENU i,0,cDisable
  339.   next
  340. END SUB
  341.  
  342. SUB menus_on
  343.   for i=mProject to mHelp
  344.     MENU i,0,cEnable
  345.   next
  346. END SUB
  347.  
  348. SUB show_free_mem(ADDRESS wdw)
  349. SHARED vernum
  350. STRING title SIZE 80
  351.     '..show free memory in main window.
  352.     title = "AIDE version "+vernum
  353.     title = title + "    Free Memory: "
  354.     title = title + str$(FRE(-1))+" bytes"
  355.     SetWindowTitles(wdw,title,LEAVE)
  356. END SUB
  357.  
  358. SUB clean_up
  359. SHARED config
  360.   '..delete tmpdir files 
  361.   SYSTEM "delete >NIL: "+quote(config->tmpdir+"#?")
  362.   KILL "ace.err"
  363. END SUB
  364.  
  365. {------------------------------------------------------}
  366.  
  367. SUB abort_prog(STRING fname)
  368.   BEEP
  369.   PRINT fname;" error!"
  370.   PRINT
  371.   PRINT "press Q key to quit."
  372.   WHILE UCASE$(INKEY$)<>"Q":SLEEP:WEND
  373.   WINDOW CLOSE 1
  374.   STOP
  375. END SUB
  376.  
  377. SUB STRING strip_whitespace(STRING X)
  378. SHORTINT i,j,length
  379. STRING   ch SIZE 2
  380.   '..remove leading whitespace from X.
  381.   length = LEN(X)
  382.  
  383.   i=1
  384.   repeat
  385.     ch = MID$(X,i,1)
  386.     if ch <= " " then ++i
  387.   until ch > " " or i > length
  388.  
  389.   '..return the stripped string.
  390.   strip_whitespace = MID$(X,i)
  391. END SUB
  392.  
  393. SUB append_slash(ADDRESS X_addr)
  394. STRING X ADDRESS X_addr
  395. STRING delimiter SIZE 2
  396.     delimiter = RIGHT$(X,1)
  397.     if delimiter <> "/" and delimiter <> ":" then 
  398.       X = X+"/" 
  399.     end if
  400. END SUB
  401.  
  402. SUB get_config
  403. SHARED   config
  404. CONST    words=8
  405. DIM      keyword$(words) SIZE 9
  406. SHORTINT i,posn
  407. STRING   config_file SIZE 12
  408. STRING   ln SIZE 81
  409. STRING   value SIZE strSize
  410.  
  411.   config_file = "AIDE.config"
  412.  
  413.   '..read the config file keywords
  414.   for i=1 to words
  415.     read keyword$(i)
  416.   next
  417.   DATA EDITOR,VIEWER,CALCTOOL,AGDTOOL
  418.   DATA TMPDIR,DOCDIR,SRCDIR,BLTDIR
  419.  
  420.   '..open the configuration file
  421.   OPEN "I",#1,config_file
  422.  
  423.   '..abort program if we can't open this!
  424.   if HANDLE(1)=NULL then CALL abort_prog(config_file)
  425.  
  426.   '..search for config keywords and set 
  427.   '..values in config structure (expects: <configvar>=<value>).
  428.   while not eof(1)
  429.     LINE INPUT #1,ln
  430.     ln = UCASE$(ln)
  431.     if LEFT$(ln,1) <> "#" then
  432.       i=1 : posn=0
  433.       while i<=words and posn=0
  434.         posn=INSTR(ln,keyword$(i))
  435.         if posn=0 then ++i
  436.       wend
  437.       if posn > 0 then     
  438.      value = strip_whitespace(MID$(ln,INSTR(ln,"=")+1))
  439.     case
  440.       i=1 : config->editor  = value
  441.           i=2 : config->viewer  = value
  442.       i=3 : config->calc    = value
  443.       i=4 : config->agdtool = value
  444.           i=5 : config->tmpdir  = value
  445.       i=6 : config->docdir  = value
  446.       i=7 : config->srcdir  = value    
  447.       i=8 : config->bltdir  = value    
  448.         end case
  449.       end if
  450.     end if
  451.   wend
  452.   CLOSE #1
  453.  
  454.   '..Check we've got all the values, using defaults where necessary.
  455.  
  456.   if config->editor="" then
  457.     config->editor="c:Ed"
  458.   end if
  459.  
  460.   if config->viewer="" then
  461.     config->viewer="ACE:bin/muchmore"
  462.   end if
  463.  
  464.   if config->calc<>"" then MENU mUtils,iCalc,cEnable
  465.  
  466.   if config->tmpdir="" then 
  467.     config->tmpdir="T:"
  468.   else
  469.     append_slash(@config->tmpdir)
  470.     '.."Ram Disk:" will cause Blink to choke
  471.     '..since it can't handle quoted args, and the 2.04
  472.     '..ASL file requester yields this name for "RAM:"
  473.     if LEFT$(config->tmpdir,9) = "RAM DISK:" then
  474.        config->tmpdir = "RAM:"+MID$(config->tmpdir,10)
  475.     end if    
  476.   end if
  477.  
  478.   if config->docdir="" then
  479.     config->docdir = "ACE:docs/"
  480.   else
  481.     append_slash(@config->docdir)  
  482.   end if
  483.  
  484.   if config->srcdir<>"" then 
  485.     append_slash(@config->srcdir)  
  486.   end if
  487.  
  488.   if config->bltdir<>"" then 
  489.     append_slash(@config->bltdir)  
  490.   end if
  491. END SUB
  492.  
  493. SUB initialise_config
  494. SHARED config
  495.   config->editor=""
  496.   config->viewer=""
  497.   config->tmpdir=""
  498.   config->docdir=""
  499.   config->bltdir=""
  500.   config->agdtool=""
  501.   config->calc=""
  502. END SUB
  503.  
  504. SUB initialise_program_info
  505. SHARED prog, config
  506.   prog->source_file=""
  507.   prog->source_dir=config->srcdir
  508.   prog->made=FALSE
  509.   prog->module_count=0
  510.   prog->default_args=""
  511.   prog->xtn=""
  512. END SUB
  513.  
  514. SUB LONGINT truth(x$,SHORTINT posn)
  515.   if mid$(x$,posn,1)="T" then
  516.      truth = TRUE
  517.   else
  518.      truth = FALSE
  519.   end if
  520. END SUB
  521.  
  522. SUB show_compiler_option_status(LONGINT opt,SHORTINT opt_num)
  523.   if opt = TRUE then
  524.      MENU mCompiler,opt_num,cCheck
  525.   else
  526.      MENU mCompiler,opt_num,cEnable
  527.   end if
  528. END SUB
  529.  
  530. SUB initialise_options
  531. SHARED options
  532.   '..set defaults
  533.   options->preprocess=TRUE
  534.   options->user_break=FALSE
  535.   options->asm_comments=FALSE
  536.   options->create_icon=FALSE
  537.   options->list_lines=FALSE
  538.   options->optimise=TRUE
  539.   options->window_close=FALSE
  540.  
  541.   '..check for options file
  542.   if fexists("AIDE.options") then
  543.     OPEN "I",#1,"AIDE.options"
  544.     IF NOT EOF(1) THEN LINE INPUT #1,opt$
  545.     CLOSE #1
  546.     if LEN(opt$) = 7 then
  547.       options->preprocess=truth(opt$,1)
  548.       options->user_break=truth(opt$,2)
  549.       options->asm_comments=truth(opt$,3)
  550.       options->create_icon=truth(opt$,4)
  551.       options->list_lines=truth(opt$,5)
  552.       options->optimise=truth(opt$,6)
  553.       options->window_close=truth(opt$,7)
  554.     else
  555.       PRINT "Format error in AIDE.options!"
  556.     end if  
  557.   end if
  558.  
  559.   '..show whether each is active.
  560.   show_compiler_option_status(options->preprocess,iPreProcess)
  561.   show_compiler_option_status(options->user_break,iBreak)
  562.   show_compiler_option_status(options->asm_comments,iComments)
  563.   show_compiler_option_status(options->create_icon,iIcon)
  564.   show_compiler_option_status(options->list_lines,iListLines)
  565.   show_compiler_option_status(options->optimise,iOptimise)
  566.   show_compiler_option_status(options->window_close,iWindow)
  567. END SUB
  568.  
  569. SUB initialise_environment
  570. SHARED module$
  571.   initialise_config
  572.   get_config
  573.   initialise_options
  574.   initialise_program_info
  575.   '..clear link modules array
  576.   for i=1 to maxModules:module$(i)="":next
  577. END SUB
  578.  
  579. {------------------------------------------------------}
  580.  
  581. SUB setup_menus
  582. SHARED config
  583.  
  584.   '..Project Menu
  585.   MENU mProject,0,cEnable,           "Project"
  586.  
  587.   MENU mProject,iNew,cEnable,           "New","N"
  588.   MENU mProject,iOpen,cEnable,           "Open...","O"
  589.   MENU mProject,iView,cEnable,        "View...","V"
  590.   MENU mProject,iSep1.1,cDisable,      "-----------------"
  591.   MENU mProject,iDelete,cEnable,       "Delete...","D"
  592.   MENU mProject,iPrint,cEnable,           "Print...","P"
  593.   MENU mProject,iExecute,cEnable,      "Execute...","X"
  594.   MENU mProject,iShell,cEnable,        "Spawn Shell"
  595.   MENU mProject,iSep1.2,cDisable,      "-----------------"
  596.   MENU mProject,iAbout,cEnable,           "About..."
  597.   MENU mProject,iQuit,cEnable,           "Quit AIDE","Q"
  598.  
  599.   '..Program Menu
  600.   MENU mProgram,0,cEnable,           "Program"
  601.  
  602.   MENU mProgram,iSetSource,cEnable,      "Set Source...","S"
  603.   MENU mProgram,iEdit,cDisable,        "Edit Source","E"
  604.   MENU mProgram,iSep2.1,cDisable,       "------------------------"
  605.   MENU mProgram,iRun,cDisable,            "Run","R"
  606.   MENU mProgram,iRunInShell,cDisable,      "Run in Shell..."
  607.   MENU mProgram,iSep2.2,cDisable,      "------------------------"
  608.   MENU mProgram,iCompile,cDisable,      "Compile","C"
  609.   MENU mProgram,iMake,cDisable,      "Make Executable","M"
  610.   MENU mProgram,iBuild,cDisable,       "Build Application","B"
  611.   MENU mProgram,iModule,cDisable,    "Create Linkable Module"
  612.   MENU mProgram,iSep2.3,cDisable,      "------------------------"
  613.   MENU mProgram,iViewAsm,cDisable,    "View Assembly Source"
  614.   MENU mProgram,iViewPrep,cDisable,    "View Preprocessed Source"
  615.   MENU mProgram,iShowErrs,cDisable,      "View Compiler Errors"
  616.  
  617.   '..Compiler Menu
  618.   MENU mCompiler,0,cEnable,        "Compiler"
  619.  
  620.   MENU mCompiler,iPreProcess,cCheck,    "    Preprocess Source"
  621.   MENU mCompiler,iBreak,cEnable,    "    Break Trapping"
  622.   MENU mCompiler,iComments,cEnable,    "    Assembly Comments"
  623.   MENU mCompiler,iIcon,cEnable,        "    Create Icon"
  624.   MENU mCompiler,iListLines,cEnable,    "    List Source Lines"
  625.   MENU mCompiler,iOptimise,cCheck,    "    Optimise Assembly"
  626.   MENU mCompiler,iWindow,cEnable,    "    Window Trapping"
  627.   MENU mCompiler,iSep3.1,cDisable,    "---------------------"
  628.   MENU mCompiler,iSaveOpts,cEnable,    "    Save Options"
  629.  
  630.   '..Linker Menu
  631.   MENU mLinker,0,cEnable,        "Linker"
  632.  
  633.   MENU mLinker,iAddModule,cEnable,    "Add Module..."
  634.   MENU mLinker,iRemModule,cDisable,    "Remove Module..."
  635.   MENU mLinker,iRemAllMod,cDisable,     "Remove All Modules"
  636.   MENU mLinker,iSep4.1,cDisable,    STRING$(18,"-")
  637.  
  638.   '..Utilities Menu
  639.   MENU mUtils,0,cEnable,        "Utilities"
  640.  
  641.   MENU mUtils,iCalc,cDisable,        "Calculator"
  642.   MENU mUtils,iFD2BMAP,cDisable,    "Create BMAP file"
  643.   MENU mUtils,iAB2ASCII,cDisable,    "AmigaBASIC to ASCII"
  644.  
  645.   '..check for existence of FD2BMAP and AB2ASCII
  646.   if fexists("ACE:utils/fd2bmap/fd2bmap") then MENU mUtils,iFD2BMAP,cEnable
  647.   if fexists("ACE:utils/ab2ascii/ab2ascii") then MENU mUtils,iAB2ASCII,cEnable
  648.  
  649.   '..Help Menu
  650.   MENU mHelp,0,cEnable,            "Help"
  651.  
  652.   MENU mHelp,iAIDEDoc,cEnable,        "AIDE"
  653.   MENU mHelp,iSep6.1,cDisable,        "------------------"
  654.   MENU mHelp,iACEDoc,cEnable,        "Compiler"
  655.   MENU mHelp,iA68KDoc,cEnable,        "Assembler"
  656.   MENU mHelp,iBlinkDoc,cEnable,        "Linker"
  657.   MENU mHelp,iSep6.2,cDisable,        "------------------"
  658.   MENU mHelp,iACERef,cEnable,        "Language Reference"
  659.   MENU mHelp,iACEWords,cEnable,        "ACE Reserved Words"
  660.   MENU mHelp,iSep6.3,cDisable,        "------------------"
  661.   MENU mHelp,iExamples,cEnable,        "ACE Examples"
  662.   MENU mHelp,iSep6.4,cDisable,        "------------------" 
  663.   MENU mHelp,iACEHist,cEnable,        "ACE History"
  664. END SUB
  665.  
  666. {------------------------------------------------------}
  667.  
  668. SUB new_file
  669. SHARED config
  670.   SYSTEM config->editor
  671. END SUB
  672.  
  673. SUB open_file
  674. SHARED config
  675. STRING file_name SIZE strSize
  676.   file_name = FileBox$("Open")  
  677.   SYSTEM config->editor+" "+quote(file_name)
  678. END SUB
  679.  
  680. SUB view_file
  681. SHARED config
  682. STRING file_name SIZE strSize
  683.   file_name = FileBox$("View") 
  684.   SYSTEM config->viewer+" "+quote(file_name)
  685. END SUB
  686.  
  687. SUB execute_command
  688. SHARED   default_command
  689. SHARED   config
  690. STRING   command, script_call
  691. STRING   title SIZE strSize
  692. STRING   prompt SIZE strSize
  693. STRING   script_name SIZE strSize
  694. SHORTINT script_count
  695.  
  696.   prompt = "Enter Command and Arguments:"
  697.   title  = "Execute Command"
  698.  
  699.   command = InputBox$(prompt,title,default_command,170,50)
  700.  
  701.   if command <> "" then 
  702.     '..construct a shell script: must have a unique name
  703.     '..since multiple shell scripts may be in use.
  704.     script_count=0
  705.     repeat
  706.       script_name=config->tmpdir+"command-script-"+MID$(STR$(script_count),2)
  707.       ++script_count
  708.     until NOT fexists(script_name)
  709.  
  710.     OPEN "O",254,script_name
  711.     PRINT #254,"failat 11"
  712.     PRINT #254,"echo "+CHR$(34)+"*E[0;0H*E[J"+CHR$(34) '..cls
  713.     PRINT #254,"prompt "+CHR$(34)+CHR$(34)
  714.     PRINT #254,"stack 40000"
  715.     PRINT #254,command
  716.     CLOSE #254
  717.  
  718.     '..Execute it!
  719.     script_call = "NewShell "+CHR$(34)+"CON:0/90/640/100/Command Window/CLOSE"
  720.     script_call = script_call+CHR$(34)+" FROM "
  721.     script_call = script_call+script_name
  722.     SYSTEM script_call
  723.  
  724.     '..Set new default command.
  725.     default_command = command
  726.   end if
  727. END SUB
  728.  
  729. SUB print_file
  730. STRING file_name SIZE strSize
  731. STRING text_line
  732.   menus_off
  733.   file_name = FileBox$("Print")
  734.   OPEN "I",#1,file_name
  735.   if HANDLE(1) then
  736.     PRINT "Printing ";file_name;"..."
  737.     OPEN "O",#2,"PRT:"
  738.     while not eof(1)
  739.       LINE INPUT #1,text_line
  740.       PRINT #2,text_line
  741.     wend
  742.     CLOSE 1,2
  743.     CLS:LOCATE 1,1:PRINT "Done. ";file_name;" printed."
  744.   else
  745.     if file_name<>"" then print "Unable to print ";file_name
  746.   end if 
  747.   menus_on
  748. END SUB
  749.  
  750. SUB delete_file
  751. STRING file_name SIZE strSize
  752.   menus_off
  753.   file_name = FileBox$("Delete")
  754.   if file_name<>"" then 
  755.     if NOT MsgBox("Really delete "+file_name+"?","Yes","No!") then 
  756.       PRINT file_name;" not deleted."
  757.       menus_on
  758.       EXIT SUB
  759.     end if 
  760.     KILL file_name
  761.     if ERR then 
  762.       PRINT "Error while deleting!"
  763.     else
  764.       PRINT file_name;" deleted."
  765.     end if
  766.   else
  767.     PRINT "No file/directory specified."
  768.   end if
  769.   menus_on
  770. END SUB
  771.  
  772. SUB spawn_shell
  773.   SYSTEM "NewShell CON:0/90/640/100/AIDEshell/CLOSE"
  774. END SUB
  775.  
  776. SUB about_box
  777. SHARED main_wdw, vernum
  778.   SetWindowTitles(main_wdw,"AIDE version "+vernum,LEAVE)
  779.   x$="Written in ACE by David Benn "+CHR$(169)+" 1994"
  780.   MsgBox x$, "OK"
  781.   show_free_mem(main_wdw)
  782. END SUB
  783.  
  784. SUB handle_project_menu(item)
  785. SHARED main_wdw
  786. SHORTINT result
  787.   show_free_mem(main_wdw)
  788.   case 
  789.     item = iNew          : new_file
  790.     item = iOpen      : open_file
  791.     item = iView    : view_file
  792.     item = iPrint     : print_file
  793.     item = iExecute    : execute_command
  794.     item = iDelete    : delete_file
  795.     item = iShell    : spawn_shell
  796.     item = iAbout     : about_box
  797.   end case  
  798. END SUB
  799.  
  800. {------------------------------------------------------}
  801.  
  802. SUB set_source
  803. SHARED  prog, config
  804. STRING  file_name SIZE strSize
  805. STRING  tmp SIZE strSize
  806. STRING  delimiter SIZE 2
  807. STRING  extension SIZE 5
  808. STRING  orig_file SIZE strSize
  809. STRING  old_source_dir SIZE strSize
  810. STRING  old_source_file SIZE strSize
  811. STRING  old_xtn SIZE strSize
  812. LONGINT posn,xtn_pos,ramdisk,dblslash,found
  813.  
  814.   '..save old path+filename components
  815.   old_source_dir = prog->source_dir
  816.   old_source_file = prog->source_file
  817.   old_xtn = prog->xtn
  818.  
  819.   '..get source file name (look in last referenced directory)
  820.   file_name = FileBox$("Select Source File", prog->source_dir)
  821.  
  822.   if file_name="" then 
  823.     PRINT "No source file specified."
  824.     EXIT SUB
  825.   end if
  826.  
  827.   '..extract directory path and file
  828.   posn=LEN(file_name)
  829.   found=FALSE
  830.   repeat
  831.     delimiter = MID$(file_name,posn,1)
  832.     if delimiter=":" or delimiter="/" then
  833.     found=TRUE
  834.     else
  835.          --posn
  836.     end if
  837.   until posn=0 or found
  838.  
  839.   if not found then 
  840.     prog->source_file = file_name
  841.     prog->source_dir = ""
  842.   else
  843.     '..source directory
  844.     prog->source_dir = LEFT$(file_name,posn)
  845.   
  846.     '..kludge for Wb 3.0 ASL requester when PARENT button
  847.     '..is selected. (??)
  848.     dblslash = INSTR(prog->source_dir,"//")
  849.     if dblslash then
  850.        tmp = prog->source_dir
  851.        prog->source_dir = MID$(tmp,1,dblslash) + MID$(tmp,dblslash+2)
  852.     end if   
  853.  
  854.     '..source file
  855.     prog->source_file = MID$(file_name,posn+1)
  856.   end if
  857.  
  858.   {*
  859.   ** Remove file extension (".b" or ".bas").
  860.   *}
  861.   xtn_pos = INSTR(prog->source_file,".bas") 
  862.  
  863.   if xtn_pos=0 then
  864.     xtn_pos = INSTR(prog->source_file,".BAS") 
  865.   end if
  866.  
  867.   if xtn_pos=0 then
  868.     xtn_pos = INSTR(prog->source_file,".b") 
  869.   end if
  870.  
  871.   if xtn_pos=0 then
  872.     xtn_pos = INSTR(prog->source_file,".B") 
  873.   end if
  874.  
  875.   if xtn_pos > 0 then extension = MID$(prog->source_file,xtn_pos)
  876.  
  877.   if extension = "" then
  878.     extension = MID$(prog->source_file,xtn_pos)  
  879.   end if
  880.   
  881.   if ucase$(extension) <> ".B" and ucase$(extension) <> ".BAS" then 
  882.     prog->xtn = ""
  883.     prog->source_file = ""
  884.   else
  885.     prog->xtn = extension    
  886.     posn = INSTR(ucase$(prog->source_file),ucase$(prog->xtn))
  887.      prog->source_file = LEFT$(prog->source_file,posn-1)
  888.   end if  
  889.  
  890.   '..Prepare for new compilation.
  891.   if prog->source_file <> "" then
  892.     clean_up
  893.     prog->default_args=""
  894.     prog->made=FALSE
  895.  
  896.     MENU mProgram,iEdit,cEnable
  897.     MENU mProgram,iRun,cEnable
  898.     MENU mProgram,iRunInShell,cEnable
  899.     MENU mProgram,iArguments,cEnable
  900.     MENU mProgram,iCompile,cEnable
  901.     MENU mProgram,iMake,cEnable
  902.     MENU mProgram,iBuild,cEnable
  903.     MENU mProgram,iModule,cEnable
  904.     MENU mProgram,iViewAsm,cEnable
  905.     MENU mProgram,iViewPrep,cEnable
  906.     MENU mProgram,iShowErrs,cEnable
  907.  
  908.     '..does the file exist? -> invoke editor if not.
  909.     if NOT fexists(prog->source_dir+prog->source_file+prog->xtn) then
  910.       orig_file = prog->source_dir+prog->source_file+prog->xtn
  911.       SYSTEM config->editor+" "+quote(orig_file)
  912.     end if
  913.     CLS:LOCATE 1,1
  914.     PRINT "Source file is ";prog->source_dir;prog->source_file;prog->xtn
  915.   else
  916.     '..invalid source
  917.     prog->source_dir = old_source_dir
  918.     prog->source_file = old_source_file
  919.     prog->xtn = old_xtn
  920.     CLS:LOCATE 1,1
  921.     PRINT "No source file specified."
  922.   end if
  923. END SUB
  924.  
  925. SUB edit_source
  926. SHARED config,prog
  927. STRING command
  928. STRING orig_file SIZE strSize
  929. DECLARE STRUCT DateStamp ds1,ds2
  930.  
  931.   orig_file = prog->source_dir+prog->source_file+prog->xtn
  932.  
  933.   IF NOT fexists(orig_file) THEN
  934.      PRINT "Unable to edit ";orig_file
  935.      EXIT SUB
  936.   END IF
  937.  
  938.   '..Get datestamp of original file before editing
  939.   get_file_datestamp(orig_file,ds1)
  940.   
  941.   '..Edit source file
  942.   SYSTEM config->editor+" "+quote(orig_file)
  943.  
  944.   '..Get datestamp of original file after editing
  945.   get_file_datestamp(orig_file,ds2)
  946.  
  947.   '..Flag file as "unmade" if it's changed;
  948.   '..delete any existing assembly source file
  949.   '..since it is now out of date.
  950.   IF datestamps_different(ds1,ds2) THEN
  951.      KILL config->tmpdir+prog->source_file+".s"
  952.      prog->made=FALSE
  953.   END IF
  954. END SUB
  955.  
  956. SUB invoke_make_script(STRING target_dir,SHORTINT object_type)
  957. SHARED  prog,config,main_wdw
  958. STRING  command
  959. STRING  msg SIZE strSize     
  960. STRING  target_file SIZE strSize     
  961. LONGINT target_ok
  962. DECLARE STRUCT DateStamp old_target,new_target
  963. CONST   BOLD=2, NORMAL=0
  964.  
  965.   menus_off
  966.   
  967.   CLS:LOCATE 1,1
  968.   STYLE BOLD
  969.   PRINT "Making ";CHR$(34);prog->source_file;CHR$(34)
  970.   STYLE NORMAL
  971.  
  972.   target_file = target_dir+prog->source_file
  973.  
  974.   '..Delete the binaries from previous compilations
  975.   '..(if there were any) so we know whether the make 
  976.   '..was successful or not.
  977.   KILL target_file
  978.   KILL target_file".o"
  979.  
  980.   '..Rename assembly source file (if it exists) with a ".old" extension.
  981.   '..This is used below to check whether a new target file has been created.
  982.   if fexists(target_file+".s") then
  983.      NAME target_file+".s" AS target_file+".old"
  984.   else
  985.      '..Create a dummy assembly source file so
  986.      '..there is something to compare the new
  987.      '..assembly source file (about to be created) to.
  988.      OPEN "O",#1,target_file+".old"
  989.      PRINT #1,"; dummy assembly source"
  990.      PRINT #1,"END"
  991.      CLOSE #1 
  992.   end if
  993.  
  994.   '..Delete old error file in case we don't generate one now
  995.   '..(ie: don't want old ace.err to be associated with current
  996.   '..compilation).
  997.   KILL "ace.err"
  998.  
  999.   '..start asynchronous process to Make the program. 
  1000.   command = "NewShell "+CHR$(34)+"CON:0/90/640/100/Make program: "
  1001.   command = command + prog->source_file+CHR$(34)
  1002.   command = command + " FROM " + config->tmpdir+"AIDE-newshell-startup"
  1003.   SYSTEM command  
  1004.  
  1005.   '..**********************************
  1006.   '..Display messages from Make process 
  1007.   '..and show free memory while waiting 
  1008.   '..for Make to complete.
  1009.   '..**********************************
  1010.   OPEN "I",#1,"PIPE:"
  1011.   time0=TIMER
  1012.   repeat
  1013.     LINE INPUT #1,msg
  1014.     if msg<>"MakeDone" and msg<>"MakeAborted" and msg<>"" then PRINT msg 
  1015.     if TIMER >= time0+1 then
  1016.     show_free_mem(main_wdw)
  1017.     time0=TIMER
  1018.     end if
  1019.   until msg = "MakeDone" or msg = "MakeAborted"
  1020.   CLOSE #1
  1021.  
  1022.   case 
  1023.     object_type = ASM : PRINT "Assembly source file ";
  1024.     object_type = EXE : PRINT "Executable file ";
  1025.     object_type = OBJ : PRINT "Linkable module ";
  1026.   end case
  1027.  
  1028.   '..***************
  1029.   '..Successful Make
  1030.   '..***************
  1031.   if msg = "MakeDone" then 
  1032.     if object_type=ASM then
  1033.        '..assembly source is target
  1034.        get_file_datestamp(target_file+".old",old_target)
  1035.        get_file_datestamp(target_file+".s",new_target)
  1036.        if fexists(target_file+".s") and older(old_target,new_target) then
  1037.       target_ok=TRUE
  1038.        else
  1039.       target_ok=FALSE
  1040.        end if
  1041.     else
  1042.        '..executable is target
  1043.        if object_type=EXE then
  1044.           target_ok=fexists(target_file)
  1045.        else
  1046.       '..linkable (object) module is target
  1047.           if object_type=OBJ then
  1048.         target_ok=fexists(target_file+".o")    
  1049.       else
  1050.         '..unknown target type!
  1051.         target_ok=FALSE
  1052.        end if
  1053.        end if
  1054.     end if
  1055.  
  1056.     if  target_ok then 
  1057.       PRINT "created."
  1058.       prog->made=TRUE
  1059.     else
  1060.       PRINT "not created."
  1061.     end if
  1062.   end if
  1063.  
  1064.   '..*****************
  1065.   '..Unsuccessful Make
  1066.   '..*****************
  1067.   if msg = "MakeAborted" then
  1068.     KILL target_dir+prog->source_file
  1069.     KILL target_dir+prog->source_file+".o"
  1070.     KILL target_dir+prog->source_file+".s"
  1071.     KILL target_dir+prog->source_file+".old"
  1072.     PRINT "not created."
  1073.     prog->made=FALSE
  1074.   end if
  1075.  
  1076.   menus_on
  1077. END SUB
  1078.  
  1079. SUB make_program(STRING target_dir,SHORTINT object_type)
  1080. SHARED   config,prog,options,module$
  1081. SHORTINT i
  1082. STRING   command,opts
  1083. STRING     ace_src_name SIZE strSize
  1084. STRING     asm_src_name SIZE strSize
  1085. DECLARE  STRUCT DateStamp ace_src,asm_src
  1086.  
  1087.   '..Generate a shell script to make the program.
  1088.   OPEN "O",#1,config->tmpdir+"AIDE-newshell-startup"
  1089.   
  1090.   PRINT #1,"failat 11"
  1091.   PRINT #1,"echo "+CHR$(34)+"*E[0;0H*E[J"+CHR$(34)
  1092.   PRINT #1,"alias QuitMake echo >PIPE: MakeAborted"
  1093.   PRINT #1,"stack 40000"
  1094.  
  1095.   ace_src_name = prog->source_dir+prog->source_file+prog->xtn
  1096.   asm_src_name = target_dir+prog->source_file+".s"
  1097.  
  1098.   '..Compare datestamps of ACE source and assembly source (if it exists!)
  1099.   get_file_datestamp(ace_src_name, ace_src)
  1100.   get_file_datestamp(asm_src_name, asm_src)
  1101.   
  1102.   '..We only want to compile the ACE source if it hasn't already been
  1103.   '..compiled (by the user selecting "Compile Program" in the past).
  1104.   IF NOT fexists(asm_src_name) OR NOT older(ace_src,asm_src) THEN
  1105.     '*** APP ***  
  1106.     IF options->preprocess THEN
  1107.       PRINT #1,"echo >PIPE: Preprocessing"
  1108.       command = "ACE:bin/app "+quote(ace_src_name)
  1109.       command = command +" "+quote(target_dir+prog->source_file+prog->xtn)
  1110.       PRINT #1,command
  1111.  
  1112.       '..preprocessor errors?
  1113.       PRINT #1,"IF ERROR"
  1114.       PRINT #1,"   echo >PIPE: Aborted!"
  1115.       PRINT #1,"   echo >PIPE: MakeAborted"
  1116.       PRINT #1,"   EndCLI"
  1117.       PRINT #1,"ENDIF"
  1118.     ELSE
  1119.       '..Just copy file verbatim if APP not invoked.
  1120.       command = "c:copy "+quote(ace_src_name)+" "
  1121.       command = command + quote(target_dir+prog->source_file+prog->xtn)
  1122.       PRINT #1,command
  1123.     END IF
  1124.  
  1125.     '*** ACE ***
  1126.     PRINT #1,"echo >PIPE: Compiling"
  1127.     command = "ACE:bin/ace -E"
  1128.  
  1129.     '..Compiler switches? (the "i" switch is redundant here since
  1130.     '..build_application copies the icon from ACE:icons/exe.info
  1131.     '..but someone MAY expect the icon to also be in the working 
  1132.     '..directory when compiling/making!)
  1133.     opts=""
  1134.     if options->user_break then opts = opts + "b"
  1135.     if options->asm_comments then opts = opts + "c"
  1136.     if options->create_icon then opts = opts + "i" 
  1137.     if options->list_lines then opts = opts + "l"
  1138.     if options->optimise then opts = opts + "O"
  1139.     if options->window_close then opts = opts + "w"
  1140.     if object_type = OBJ then opts = opts + "m"
  1141.     command = command + opts+" "
  1142.  
  1143.     command = command + quote(target_dir+prog->source_file+prog->xtn)
  1144.     PRINT #1,command
  1145.  
  1146.     '..compile-time errors?
  1147.     PRINT #1,"IF ERROR"
  1148.     PRINT #1,"   echo >PIPE: Aborted!"
  1149.     PRINT #1,"   echo >PIPE: MakeAborted"
  1150.     PRINT #1,"   EndCLI"
  1151.     PRINT #1,"ENDIF"
  1152.   END IF
  1153.  
  1154.   IF object_type = EXE OR object_type = OBJ THEN
  1155.     '*** A68K ***
  1156.     PRINT #1,"echo >PIPE: Assembling"
  1157.     command = "ACE:bin/a68k "+quote(asm_src_name)
  1158.     PRINT #1,command
  1159.  
  1160.     IF object_type = EXE THEN
  1161.       '*** BLINK ***
  1162.       PRINT #1,"echo >PIPE: Linking"
  1163.       command = "ACE:bin/blink "+target_dir+prog->source_file+".o"
  1164.       command = command + " LIB "
  1165.       '..add link modules
  1166.       for i=1 to prog->module_count
  1167.         if module$(i)<>"" then command = command + module$(i) + "+"
  1168.       next
  1169.       command = command + "ACElib:startup.lib+ACElib:db.lib+ACElib:ami.lib"
  1170.       'command = command + "SMALLCODE SMALLDATA" 
  1171.       PRINT #1,command
  1172.     END IF
  1173.   END IF
  1174.  
  1175.   '..OK -> we're finished
  1176.   PRINT #1,"echo >PIPE: MakeDone"
  1177.   PRINT #1,"EndCLI"
  1178.  
  1179.   CLOSE #1
  1180.  
  1181.   '..do it!
  1182.   invoke_make_script(target_dir,object_type)
  1183. END SUB
  1184.  
  1185. SUB compile_program
  1186. SHARED config,prog
  1187.   if not prog->made or not fexists(config->tmpdir+prog->source_file+".s") then
  1188.      make_program(config->tmpdir,ASM)
  1189.   else
  1190.      PRINT prog->source_file;" is up to date."    
  1191.   end if
  1192. END SUB
  1193.  
  1194. SUB make_executable
  1195. SHARED config,prog
  1196.   if not prog->made or not fexists(config->tmpdir+prog->source_file) then
  1197.      make_program(config->tmpdir,EXE)
  1198.   else
  1199.      PRINT prog->source_file;" is up to date."
  1200.   end if
  1201. END SUB
  1202.  
  1203. SUB run_program
  1204. SHARED config,prog
  1205.  
  1206.   make_executable
  1207.  
  1208.   if prog->made then
  1209.     menus_off
  1210.     PRINT "Running ";prog->source_file;"..."
  1211.     SYSTEM quote(config->tmpdir+prog->source_file)
  1212.     CLS:LOCATE 1,1
  1213.     PRINT prog->source_file;" finished."
  1214.     menus_on
  1215.   else
  1216.     '..There (probably) was a compile error.
  1217.     PRINT "Unable to run ";prog->source_file;"."
  1218.   end if
  1219. END SUB
  1220.  
  1221. SUB run_program_in_shell
  1222. SHARED   config,prog
  1223. STRING   prompt SIZE strSize
  1224. STRING   title SIZE strSize
  1225. STRING   script_call,arguments
  1226. STRING   script_name SIZE strSize
  1227. SHORTINT script_count
  1228.  
  1229.   make_executable
  1230.  
  1231.   if prog->made then
  1232.     menus_off
  1233.  
  1234.     '..get command-line arguments
  1235.     prompt = "Command-Line Arguments?"
  1236.     title = "Run in Shell"
  1237.     arguments = InputBox$(prompt,title,prog->default_args,170,50)
  1238.  
  1239.     '..construct a shell script: script must have a unique name
  1240.     '..since multiple shell scripts may be in use.
  1241.     script_count=0
  1242.     repeat
  1243.       script_name=config->tmpdir+"command-script-"+MID$(STR$(script_count),2)
  1244.       ++script_count
  1245.     until NOT fexists(script_name)
  1246.  
  1247.     OPEN "O",254,script_name
  1248.     PRINT #254,"failat 11"
  1249.     PRINT #254,"echo "+CHR$(34)+"*E[0;0H*E[J"+CHR$(34) '..cls
  1250.     PRINT #254,"prompt "+CHR$(34)+CHR$(34)
  1251.     PRINT #254,"stack 40000"
  1252.     PRINT #254,quote(config->tmpdir+prog->source_file)+" "+arguments
  1253.     CLOSE #254
  1254.  
  1255.     '..Execute it!
  1256.     script_call = "NewShell "+CHR$(34)
  1257.     script_call = script_call+"CON:0/90/640/100/Running "
  1258.     script_call = script_call+prog->source_file+"/CLOSE"
  1259.     script_call = script_call+CHR$(34)+" FROM "
  1260.     script_call = script_call+script_name
  1261.     SYSTEM script_call
  1262.     CLS:LOCATE 1,1
  1263.  
  1264.     '..store default arguments for program.
  1265.     prog->default_args = arguments
  1266.  
  1267.     menus_on
  1268.   else
  1269.     '..There (probably) was a compile error.
  1270.     PRINT "Unable to run ";prog->source_file;"."
  1271.   end if
  1272. END SUB
  1273.  
  1274. SUB build_application
  1275. SHARED config,prog,options
  1276. STRING command,dest_dir
  1277.  
  1278.   make_executable
  1279.  
  1280.   '..where's the executable going?
  1281.   if config->bltdir<>"" then 
  1282.      dest_dir = config->bltdir
  1283.   else
  1284.      dest_dir = prog->source_dir
  1285.   end if
  1286.   '..copy executable
  1287.   command = "sys:c/copy >NIL: "+config->tmpdir+prog->source_file+" "
  1288.   command = command + quote(dest_dir+prog->source_file)
  1289.   SYSTEM command
  1290.   '..copy icon?
  1291.   if options->create_icon then
  1292.     command = "sys:c/copy >NIL: ACE:icons/exe.info "
  1293.     command = command + quote(dest_dir+prog->source_file+".info")
  1294.     SYSTEM command
  1295.   end if
  1296.   '..were we successful?
  1297.   if prog->made then 
  1298.     PRINT dest_dir+prog->source_file;" has been built."
  1299.   end if
  1300. END SUB
  1301.  
  1302. SUB build_module
  1303. SHARED config,prog,options
  1304. STRING command,dest_dir
  1305.  
  1306.   make_program(config->tmpdir,OBJ)
  1307.  
  1308.   '..where's the linkable module going?
  1309.   if config->bltdir<>"" then 
  1310.      dest_dir = config->bltdir
  1311.   else
  1312.      dest_dir = prog->source_dir
  1313.   end if
  1314.   '..copy module
  1315.   command = "sys:c/copy >NIL: "+config->tmpdir+prog->source_file+".o "
  1316.   command = command + quote(dest_dir+prog->source_file+".o")
  1317.   SYSTEM command
  1318. END SUB
  1319.  
  1320. SUB view_assembly_source
  1321. SHARED config,prog
  1322. STRING fname SIZE strSize 
  1323.   fname = config->tmpdir+prog->source_file+".s"
  1324.   if fexists(fname) then 
  1325.     SYSTEM config->viewer+" "+quote(fname)
  1326.   else
  1327.     PRINT "No assembly source present."
  1328.   end if
  1329. END SUB
  1330.  
  1331. SUB view_preprocessed_source
  1332. SHARED config,prog
  1333. STRING fname SIZE strSize 
  1334.   fname = config->tmpdir+prog->source_file+prog->xtn
  1335.   if fexists(fname) then 
  1336.     SYSTEM config->viewer+" "+quote(fname)
  1337.   else
  1338.     PRINT "No preprocessed source present."
  1339.   end if
  1340. END SUB
  1341.  
  1342. SUB view_compiler_errors
  1343. SHARED config
  1344.   OPEN "I",#1,"ace.err"  
  1345.   if HANDLE(1) then 
  1346.     if LOF(1)<>0 then
  1347.       SYSTEM config->viewer+" ace.err"
  1348.     else
  1349.       PRINT "There were no compilation errors."
  1350.     end if
  1351.   else
  1352.     PRINT "No ACE error log."
  1353.   end if
  1354.   CLOSE #1
  1355. END SUB
  1356.  
  1357. SUB handle_program_menu(item)
  1358. SHARED main_wdw
  1359.   show_free_mem(main_wdw)
  1360.   case
  1361.     item = iSetSource    : set_source
  1362.     item = iEdit    : edit_source
  1363.     item = iRun        : run_program
  1364.     item = iRunInShell    : run_program_in_shell
  1365.     item = iCompile      : compile_program
  1366.     item = iMake    : make_executable
  1367.     item = iBuild    : build_application
  1368.     item = iModule    : build_module
  1369.     item = iViewAsm    : view_assembly_source
  1370.     item = iViewPrep    : view_preprocessed_source
  1371.     item = iShowErrs    : view_compiler_errors
  1372.   end case
  1373. END SUB
  1374.  
  1375. {------------------------------------------------------}
  1376.  
  1377. SUB change_option_state(ADDRESS opt,SHORTINT item)
  1378.   if NOT *&opt then
  1379.     *&opt:=TRUE
  1380.     MENU mCompiler,item,cCheck
  1381.   else
  1382.     *&opt:=FALSE
  1383.     MENU mCompiler,item,cEnable
  1384.   end if
  1385. END SUB
  1386.  
  1387. SUB write_option(LONGINT opt_val)
  1388.   if opt_val = TRUE then
  1389.      PRINT #1,"T";
  1390.   else
  1391.      PRINT #1,"F";
  1392.   end if
  1393. END SUB
  1394.  
  1395. SUB handle_compiler_menu(item)
  1396. SHARED  options,config,prog,main_wdw
  1397. ADDRESS opt
  1398.   show_free_mem(main_wdw)
  1399.   if item <= iWindow then
  1400.     '..toggle a compiler option
  1401.     case
  1402.       item = iPreProcess: opt = @options->preprocess
  1403.       item = iBreak    : opt = @options->user_break
  1404.       item = iComments    : opt = @options->asm_comments
  1405.       item = iIcon    : opt = @options->create_icon
  1406.       item = iListLines    : opt = @options->list_lines
  1407.       item = iOptimise    : opt = @options->optimise
  1408.       item = iWindow    : opt = @options->window_close
  1409.     end case
  1410.  
  1411.     change_option_state(opt,item)
  1412.  
  1413.     '..previous MAKEs are invalidated
  1414.     clean_up
  1415.     prog->made = FALSE    
  1416.   else
  1417.     if item = iSaveOpts then
  1418.       '..save current option settings
  1419.       OPEN "O",#1,"AIDE.options"
  1420.       write_option(options->preprocess)
  1421.       write_option(options->user_break)
  1422.       write_option(options->asm_comments)
  1423.       write_option(options->create_icon)
  1424.       write_option(options->list_lines)
  1425.       write_option(options->optimise)
  1426.       write_option(options->window_close)
  1427.       PRINT #1,CHR$(10)
  1428.       CLOSE #1
  1429.       PRINT "Compiler options saved."
  1430.     end if
  1431.   end if
  1432. END SUB
  1433.  
  1434. {------------------------------------------------------}
  1435.  
  1436. SUB add_link_module
  1437. SHARED   module$,prog
  1438. SHORTINT maxMod,i
  1439. LONGINT  found
  1440. STRING   module SIZE strSize
  1441.  
  1442.   '..add a module to the list of object files to link.
  1443.  
  1444.   maxMod = prog->module_count + 1
  1445.  
  1446.   if maxMod <= maxModules then
  1447.     '..get name of module
  1448.     module = FileBox$("Add Module")
  1449.  
  1450.     if module <> "" then 
  1451.       '.."Ram Disk:" will cause Blink to choke
  1452.       '..since it can't handle quoted args, and the 2.04
  1453.       '..ASL file requester yields this name for "RAM:"
  1454.       if UCASE$(LEFT$(module,9)) = "RAM DISK:" then
  1455.         module = "RAM:"+MID$(module,10)
  1456.       end if    
  1457.       
  1458.       '..is module already in the list?
  1459.       found=FALSE
  1460.       for i=1 to prog->module_count
  1461.     if module$(i) = module then found=TRUE
  1462.       next
  1463.  
  1464.       if not found then
  1465.     '..No -> add module to list
  1466.         module$(maxMod) = module
  1467.         MENU mLinker,iSep4.1+maxMod,cEnable,module$(maxMod)
  1468.     
  1469.         '..increment module count
  1470.         prog->module_count = prog->module_count + 1
  1471.        
  1472.      '..program may need to be remade
  1473.     prog->made=FALSE
  1474.  
  1475.     PRINT module$(maxMod);" added to list."
  1476.  
  1477.         '..enable "remove" menu items when there is 1 module in the list.
  1478.         if prog->module_count = 1 then 
  1479.           MENU mLinker,iRemModule,cEnable
  1480.           MENU mLinker,iRemAllMod,cEnable
  1481.         end if
  1482.       else
  1483.         PRINT module;" already in list."
  1484.       end if
  1485.     else
  1486.       PRINT "No module specified."
  1487.     end if
  1488.   else
  1489.     PRINT "No more than";maxModules;"modules can be specified."
  1490.   end if
  1491. END SUB
  1492.  
  1493. SUB remove_link_module
  1494. SHARED   module$,prog 
  1495. SHORTINT maxMod,n,i
  1496. LONGINT  found
  1497. STRING   module SIZE strSize
  1498.  
  1499.   '..remove a module from the list of files to link.
  1500.   maxMod = prog->module_count
  1501.  
  1502.   if maxMod > 0 then
  1503.     '..get module name
  1504.     module = FileBox$("Remove Module")
  1505.  
  1506.     '..remove module from list if it exists.
  1507.     if module <> "" then
  1508.       found=FALSE
  1509.       for n=1 to maxMod
  1510.         if module$(n) = module and not found then 
  1511.        found=TRUE 
  1512.        module$(n)=""
  1513.         end if
  1514.       next
  1515.  
  1516.       if found then
  1517.       '..restore module list
  1518.       CLS:LOCATE 1,1
  1519.        PRINT "Updating..."
  1520.           '..shuffle module list entries
  1521.           for n=1 to MaxMod
  1522.             for i=maxMod to 2 step -1
  1523.           if module$(i-1) = "" then 
  1524.          module$(i-1) = module$(i)  
  1525.          module$(i) = ""
  1526.           end if
  1527.             next
  1528.           next
  1529.         '.fix menus
  1530.           menu clear
  1531.           setup_menus
  1532.       enable_misc_menu_items
  1533.            MENU mLinker,iRemModule,cEnable
  1534.       MENU mLinker,iRemAllMod,cEnable
  1535.              for i=1 to maxMod
  1536.         if module$(i)<>"" then MENU mLinker,iSep4.1+i,cEnable,module$(i)
  1537.       next
  1538.       CLS:LOCATE 1,1
  1539.  
  1540.       '. decrement module count
  1541.           prog->module_count = prog->module_count - 1
  1542.  
  1543.        '..program may need to be remade
  1544.       prog->made=FALSE
  1545.  
  1546.       '..disable "remove" menu items if all have been removed.
  1547.       if prog->module_count = 0 then 
  1548.          MENU mLinker,iRemModule,cDisable
  1549.          MENU mLinker,iRemAllMod,cDisable
  1550.       end if
  1551.       else
  1552.           PRINT module;" not in list."
  1553.       end if
  1554.     else
  1555.       PRINT "No module specified."
  1556.     end if
  1557.   else
  1558.     PRINT "No modules to remove."
  1559.   end if
  1560. END SUB
  1561.  
  1562. SUB remove_all_modules
  1563. SHARED   prog,module$
  1564. SHORTINT i
  1565.   CLS:LOCATE 1,1  
  1566.   PRINT "Updating..."
  1567.   menu clear
  1568.   setup_menus
  1569.   enable_misc_menu_items
  1570.   for i=1 to maxModules
  1571.     module$(i)=""
  1572.   next
  1573.   CLS:LOCATE 1,1
  1574.   '..no modules left
  1575.   prog->module_count = 0
  1576.   '..program may need to be remade
  1577.   prog->made=FALSE
  1578. END SUB
  1579.  
  1580. SUB handle_linker_menu(item)
  1581. SHARED main_wdw
  1582.   show_free_mem(main_wdw)
  1583.   case
  1584.     item = iAddModule : add_link_module 
  1585.     item = iRemModule : remove_link_module
  1586.     item = iRemAllMod : remove_all_modules
  1587.   end case
  1588. END SUB
  1589.  
  1590. {------------------------------------------------------}
  1591.  
  1592. SUB calculator
  1593. SHARED config
  1594.   '..invoke calculator
  1595.   if config->calc<>"" and fexists(config->calc) then
  1596.     SYSTEM config->calc
  1597.   else
  1598.     PRINT "Unable to invoke calculator."
  1599.     PRINT "Check CALCTOOL entry in AIDE.config."
  1600.   end if
  1601. END SUB
  1602.  
  1603. SUB fd2bmap
  1604. STRING fd_file SIZE strSize
  1605. STRING command
  1606.  
  1607.   '..create a .bmap file for a library
  1608.   '..(assumes ACE:utils/fd2bmap/fd2bmap 
  1609.   '..and ACEbmaps: exist).
  1610.   
  1611.   menus_off
  1612.  
  1613.   fd_file = FileBox$("Select FD file for library")
  1614.  
  1615.   if fd_file = "" then
  1616.     PRINT "No FD file specified."
  1617.   else
  1618.     fd_file = LEFT$(fd_file,INSTR(fd_file,"_")-1)
  1619.     PRINT "Creating ";fd_file;".bmap..."
  1620.     SYSTEM "ACE:utils/fd2bmap/fd2bmap "+fd_file+" ACEbmaps:"
  1621.     CLS:LOCATE 1,1:PRINT "Done. BMAP file stored in ACEbmaps:"
  1622.   end if
  1623.  
  1624.   menus_on
  1625. END SUB
  1626.  
  1627. SUB ab2ascii
  1628. STRING ab_file SIZE strSize
  1629.   '..convert a compressed AmigaBASIC file to ASCII
  1630.   '..(assumes ACE:utils/ab2ascii/ab2ascii exists).
  1631.   
  1632.   menus_off
  1633.  
  1634.   ab_file = FileBox$("Select file to convert")
  1635.  
  1636.   if ab_file = "" then
  1637.     PRINT "No compressed AmigaBASIC file specified."
  1638.   else
  1639.     PRINT "Converting ";ab_file;"..."
  1640.     SYSTEM "ACE:utils/ab2ascii/ab2ascii <"+ab_file+" >"+ab_file+".b"
  1641.     CLS:LOCATE 1,1:PRINT "Done. ASCII source file ";ab_file;".b created."
  1642.   end if
  1643.  
  1644.   menus_on
  1645. END SUB
  1646.  
  1647. SUB handle_utils_menu(item)
  1648. SHARED main_wdw
  1649.   show_free_mem(main_wdw)
  1650.   case
  1651.     item = iCalc     : calculator
  1652.     item = iFD2BMAP     : fd2bmap
  1653.     item = iAB2ASCII     : ab2ascii
  1654.   end case
  1655. END SUB
  1656.  
  1657. {------------------------------------------------------}
  1658.  
  1659. SUB aide_doc
  1660. SHARED config
  1661.   '..aide.doc or aide.guide should be in one of two directories.
  1662.   if config->agdtool="" then
  1663.       '..AmigaGuide not installed -> use aide.doc
  1664.     IF fexists(config->docdir+"aide.doc") THEN
  1665.        SYSTEM config->viewer+" "+config->docdir+"aide.doc"
  1666.     ELSE
  1667.          SYSTEM config->viewer+" ACE:AIDE/aide.doc"
  1668.      END IF       
  1669.   else
  1670.     '..AmigaGuide installed -> use aide.guide
  1671.     IF fexists(config->docdir+"aide.guide") THEN
  1672.        SYSTEM config->agdtool+" "+config->docdir+"aide.guide"
  1673.     ELSE
  1674.          SYSTEM config->agdtool+" ACE:AIDE/aide.guide"
  1675.     END IF
  1676.   end if    
  1677. END SUB
  1678.  
  1679. SUB ace_doc
  1680. SHARED config
  1681.   if config->agdtool="" then
  1682.     '..AmigaGuide not installed -> use ace.doc
  1683.       SYSTEM config->viewer+" "+config->docdir+"ace.doc"
  1684.   else
  1685.     '..AmigaGuide installed -> use ace.guide
  1686.       SYSTEM config->agdtool+" "+config->docdir+"ace.guide"
  1687.   end if    
  1688. END SUB
  1689.  
  1690. SUB a68k_doc
  1691. SHARED config
  1692.   SYSTEM config->viewer+" "+config->docdir+"a68k.doc"
  1693. END SUB
  1694.  
  1695. SUB blink_doc
  1696. SHARED config
  1697.   SYSTEM config->viewer+" "+config->docdir+"blink.doc"
  1698. END SUB
  1699.  
  1700. SUB ace_ref
  1701. SHARED config
  1702.   if config->agdtool="" then
  1703.     '..AmigaGuide not installed -> use ref.doc
  1704.       SYSTEM config->viewer+" "+config->docdir+"ref.doc"
  1705.   else
  1706.     '..AmigaGuide installed -> use ref.guide
  1707.       SYSTEM config->agdtool+" "+config->docdir+"ref.guide"
  1708.   end if    
  1709. END SUB
  1710.  
  1711. SUB ace_reserved_words
  1712. SHARED config
  1713.   if fexists("ACE:docs/ace-rwords") then 
  1714.     SYSTEM config->viewer+" ACE:docs/ace-rwords"
  1715.   else
  1716.     PRINT "Unable to find ACE:docs/ace-rwords. Type:"
  1717.     PRINT 
  1718.     PRINT "  ACE WORDS > ACE:docs/ace-rwords"
  1719.     PRINT
  1720.     PRINT "from a shell prompt. Then select menu option again."
  1721.   end if
  1722. END SUB
  1723.  
  1724. SUB ace_examples
  1725. SHARED config
  1726.   if config->agdtool<>"" then
  1727.     SYSTEM config->agdtool+" ACE:docs/Example.Guide"
  1728.   end if
  1729. END SUB
  1730.  
  1731. SUB ace_history
  1732. SHARED config
  1733.   SYSTEM config->viewer+" "+config->docdir+"history"
  1734. END SUB
  1735.  
  1736. SUB handle_help_menu(item)
  1737. SHARED main_wdw
  1738.   show_free_mem(main_wdw)
  1739.   case
  1740.     item = iAIDEDoc     : aide_doc
  1741.     item = iACEDoc     : ace_doc
  1742.     item = iA68KDoc     : a68k_doc
  1743.     item = iBlinkDoc     : blink_doc
  1744.     item = iACERef     : ace_ref
  1745.     item = iACEWords     : ace_reserved_words
  1746.     item = iExamples    : ace_examples
  1747.     item = iACEHist     : ace_history
  1748.   end case
  1749. END SUB
  1750.  
  1751. {------------------------------------------------------}
  1752.  
  1753. SUB event_loop(SHORTINT first_menu_selection)
  1754. SHARED main_wdw
  1755. SHORTINT menuNum,itemNum
  1756.   REPEAT
  1757.     show_free_mem(main_wdw)
  1758.  
  1759.     '..await menu activity
  1760.     menu wait
  1761.  
  1762.     if first_menu_selection then 
  1763.     CLS   '..remove initial "Select a menu option" message.
  1764.     LOCATE 1,1
  1765.     first_menu_selection = FALSE
  1766.     end if
  1767.  
  1768.     '..handle menu
  1769.     menuNum = MENU(0)
  1770.     itemNum = MENU(1)
  1771.     case 
  1772.       menuNum = mProject  : handle_project_menu(itemNum)
  1773.       menuNum = mProgram  : handle_program_menu(itemNum)
  1774.       menuNum = mCompiler : handle_compiler_menu(itemNum)
  1775.       menuNum = mLinker   : handle_linker_menu(itemNum)
  1776.       menuNum = mUtils      : handle_utils_menu(itemNum)
  1777.       menuNum = mHelp     : handle_help_menu(itemNum)
  1778.     end case    
  1779.   UNTIL menuNum = mProject and itemNum = iQuit
  1780. END SUB
  1781.  
  1782.  
  1783. {*
  1784. ** Main Program
  1785. *}
  1786.  
  1787. window 1,"AIDE version "+vernum,(0,10)-(640,90),22
  1788. main_wdw = WINDOW(7)
  1789. if SYSTEM >= 37 then
  1790.   print "please wait..."
  1791.   setup_menus
  1792.   initialise_environment
  1793.   CLS:LOCATE 1,1
  1794.   print "Select a menu option."
  1795.   event_loop(TRUE)
  1796.   clean_up
  1797. else
  1798.   MsgBox "Need Wb 2.04 or higher. See AIDE.doc for more.", "OK"
  1799. end if
  1800. window close 1
  1801.